package org.zhxy.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import org.zhxy.model.entity.Clazz;
import org.zhxy.model.result.Result;
import org.zhxy.service.ClazzService;

import java.util.List;

@Slf4j
@Tag(name = "班级管理")
@RestController
@RequestMapping("/sms/clazzController")
@RequiredArgsConstructor
public class ClazzController {
    private final ClazzService clazzService;

    @Operation(summary = "分页条件查询年级列表")
    @GetMapping("/getClazzsByOpr/{pageNo}/{pageSize}")
    public Result getClazzsByOpr(@PathVariable("pageNo") Integer pageNo, @PathVariable("pageSize") Integer pageSize, Clazz clazz) {
        log.info("分页条件查询年级列表，请求参数：{},{},{}", pageNo, pageSize, clazz);

        IPage<Clazz> page = new Page<>(pageNo, pageSize);
        clazzService.page(page, clazz);
        log.info("分页条件查询年级列表，响应数据：{}", page);

        return Result.ok(page);
    }

    @Operation(summary = "保存或更新班级信息")
    @PostMapping("/saveOrUpdateClazz")
    public Result saveOrUpdateClazz(@RequestBody Clazz clazz) {
        log.info("保存或更新班级信息，请求参数：{}", clazz);

        clazzService.saveOrUpdate(clazz);

        return Result.ok();
    }

    @Operation(summary = "批量删除班级信息")
    @DeleteMapping("/deleteClazz")
    public Result deleteClazzByIds(@RequestBody List<Integer> ids) {
        log.info("批量删除班级信息，请求参数：{}", ids);

        clazzService.removeByIds(ids);

        return Result.ok();
    }

    @Operation(summary = "查询所有班级信息")
    @GetMapping("/getClazzs")
    public Result getClazzs() {
        List<Clazz> clazzList = clazzService.list();
        log.info("查询所有班级信息，响应数据：{}", clazzList);

        return Result.ok(clazzList);
    }
}
